﻿using System;
using System.Collections.Generic;
using System.Linq;
using LDM.Sys.Repository.Interfaces;
using LDM.Sys.ServiceAPI.Model.DBModel;
using LDM.Sys.ServiceAPI.Model.ViewModel.Request.AuthorityReq;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Model.Enum.ConfigModel;
using Model.Models;
using Utility.DB.SqlSugar;
using Utility.Extensions;
namespace LDM.Sys.Repository.Repository
{
    /// <summary>
    /// 用户角色仓储
    /// </summary>
    public class SysRoleRepository : DbContextBase<SysRole>, ISysRoleRepository, IScoped
    {
        public SysRoleRepository(IConfiguration configuration) :
           base(configuration.GetConnectionString(ConnectionStringType.UserMysql.GetDescription()))
        {
        }

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <returns></returns>
        public PageResult<SysRole> GetSysRoles(GetSysRoleReq request)
        {
            int totalCount = 0;
            var queryResut = Db.Queryable<SysRole>()
                .WhereIF(!string.IsNullOrEmpty(request.RoleCode), x => x.RoleCode.Contains(request.RoleCode))
                .WhereIF(!string.IsNullOrEmpty(request.RoleName), x => x.RoleName.Contains(request.RoleName))
                .ToPageList(request.Pagenumber, request.PageSize, ref totalCount);
            return PageResult<SysRole>.CreateInstance(queryResut, totalCount);
        }
    }
}
